package com.zzx.exception;

import com.alibaba.fastjson.JSON;
import com.zzx.util.ResponseResult;
import com.zzx.util.ResponseWrite;
import org.apache.catalina.filters.ExpiresFilter;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 全局异常
 */
@RestControllerAdvice
@RestController
public class GlobalException{

    @ExceptionHandler(value = {SystemException.class})
    public ResponseResult SystemException(SystemException e){
        e.printStackTrace();
        System.out.println("system");
     ResponseResult<String> stringResponseResult = new ResponseResult<>(e.getMsg());

     return stringResponseResult;

    }
    @ExceptionHandler(value = {RuntimeException.class})
    public ResponseResult Runtime(RuntimeException runtimeException){
        runtimeException.printStackTrace();
        ResponseResult<String> stringResponseResult = new ResponseResult(runtimeException.getMessage(),ExceptionState.UNKNOWN);
        return stringResponseResult;
    }
    @ExceptionHandler(value = {Exception.class})
    public ResponseResult SystemException(Exception e){
        e.printStackTrace();
        return new ResponseResult().UNKNOWN(e.getMessage());

    }
}


